import storage from 'good-storage';

// 处理登录成功后逻辑
/**
 * 
 * @param {Object} param that: this, res: 登录成功回调 initPwd：是否初始密码  isOtherLoginType是否其他方式登录
 */
export const handleLogin = ({ that, res, initPwd = false, isOtherLoginType = false }) => {
  if (res.data.result.departments[0].town == '里水镇') {
    storage.session.set('lishui', true);
  } else {
    storage.session.set('lishui', false);
  }
  storage.session.set('realname', res.data.result.realname);
  storage.session.set(
    'department',
    JSON.stringify(res.data.result.departments)
  );
  storage.session.set(
    'dep_name',
    res.data.result.departments[0].name
  );
  storage.session.set(
    'level',
    res.data.result.departments[0].level
  );
  storage.session.set('username', res.data.result.username);
  storage.session.set('token', res.data.result.token);
  storage.session.set('userid', res.data.result.userid);
  storage.session.set('_id', res.data.result._id);
  storage.session.set(
    'roles',
    JSON.stringify(res.data.result.roles)
  );
  storage.session.set('position', res.data.result.position);
  storage.session.set('head', res.data.result.head);
  storage.session.set(
    'sideNav',
    JSON.stringify(res.data.result.nav_item)
  );
  storage.session.set(
    'sideNav2',
    JSON.stringify(res.data.result.data_nav)
  );
  storage.session.set('type', res.data.result.user_type);
  storage.session.set('swuid', res.data.result.swuid);
  storage.session.set('num', 1);
  storage.session.set('edit_pwd', res.data.result.edit_pwd);
  storage.session.set('isInitPwd', initPwd);
  storage.session.set('isOtherLoginType', isOtherLoginType);
  that.$router.push('/home');
}